package com.etone.fileServer.controller;

import com.etone.fileServer.dto.file.FileMakeDTO;
import com.etone.fileServer.dto.file.FileMoveOrCopyDTO;
import com.etone.fileServer.dto.file.FileRenameDTO;
import com.etone.fileServer.service.FileManagerService;
import com.etone.fileServer.vo.file.FileVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.AllArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author: sovy
 * @date: 2020/11/4
 * @description:
 */
@AllArgsConstructor
@RestController
@Api(tags = "文件管理", value = "FileMangerController")
public class FileMangerController {
    private FileManagerService fileManagerService;

    @ApiOperation(value = "文件列表《完》")
    @GetMapping("/files/list")
    private List<FileVO> list(
            @ApiParam(value = "目录") @RequestParam String path,
            @ApiParam(value = "时间戳") @RequestParam Long timestamp,
            @ApiParam(value = "密文") @RequestParam String sign
    ) {
        return fileManagerService.list(path, timestamp, sign);
    }

    @ApiOperation(value = "文件重命名《完》")
    @PutMapping("/files/rename")
    public void rename(
            @ApiParam(value = "时间戳") @RequestParam Long timestamp,
            @ApiParam(value = "密文") @RequestParam String sign,
            @ApiParam(value = "文件重命名信息") @RequestBody @Validated FileRenameDTO fileRenameDTO
    ) {
        fileManagerService.rename(fileRenameDTO, timestamp, sign);
    }

    @ApiOperation(value = "文件移动《完》")
    @PutMapping("/files/move")
    public void move(
            @ApiParam(value = "时间戳") @RequestParam Long timestamp,
            @ApiParam(value = "密文") @RequestParam String sign,
            @ApiParam(value = "文件移动信息") @RequestBody @Validated List<FileMoveOrCopyDTO> fileMoveOrCopyDTOS
    ) {
        fileManagerService.move(fileMoveOrCopyDTOS, timestamp, sign);
    }

    @ApiOperation(value = "文件复制《完》")
    @PutMapping("/files/copy")
    public void copy(
            @ApiParam(value = "时间戳") @RequestParam Long timestamp,
            @ApiParam(value = "密文") @RequestParam String sign,
            @ApiParam(value = "文件复制信息") @RequestBody @Validated List<FileMoveOrCopyDTO> fileMoveOrCopyDTOS
    ) {
        fileManagerService.copy(fileMoveOrCopyDTOS, timestamp, sign);
    }

    @ApiOperation(value = "文件删除《完》")
    @DeleteMapping("/files/delete")
    public void delete(
            @ApiParam(value = "时间戳") @RequestParam Long timestamp,
            @ApiParam(value = "密文") @RequestParam String sign,
            @ApiParam(value = "文件或者目录") @RequestParam List<String> files
    ) {
        fileManagerService.delete(files, timestamp, sign);
    }

    @ApiOperation(value = "新建文件夹《完》")
    @PostMapping("/files/mkdir")
    public void mkdir(
            @ApiParam(value = "时间戳") @RequestParam Long timestamp,
            @ApiParam(value = "密文") @RequestParam String sign,
            @ApiParam(value = "新建文件") @RequestBody @Validated FileMakeDTO fileMakeDTO
    ) {
        fileManagerService.mkdir(fileMakeDTO, timestamp, sign);
    }
}
